/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.reference;

import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.exception.ObjectNotFoundExeption;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.register.Register;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 *
 * @author jorge
 */
public class ManagerReference extends Reference {

    public static int SERVER = 1, CHAT  = 2, CLIENT = 3, SERVICE_NEWS = 4;
    private static ManagerReference manegerReference;

    private ManagerReference() {
    }
    
    public static ManagerReference getInstance() {
        if (manegerReference == null) {
            synchronized (ManagerReference.class) {
                if (manegerReference == null) {
                    manegerReference = new ManagerReference();
                    manegerReference.addNext(new ChatReference());
                    manegerReference.addNext(new ClientReference());
                    manegerReference.addNext(new ServerReference());
                }
            }
        }

        return manegerReference;
    }
    

    @Override
    public Remote getReference(int actor, String url) throws NotBoundException, MalformedURLException, RemoteException, ObjectNotFoundExeption {
       Remote remote;
        if(next != null){
           remote =  (Remote)  next.getReference(actor, url);
        }else{
            throw new ObjectNotFoundExeption();
        }
       return remote;
    }
    
    
    
}
